package com.sxr.signature.sdk.api;

import com.sxr.signature.SignRequest;
import com.sxr.signature.sdk.core.KeyPairDo;
import com.sxr.signature.sdk.core.SignatureService;
import com.sxr.signature.sdk.core.imp.HmacSignatureService;
import com.sxr.signature.sdk.core.imp.SignatureServiceImp;

public class SignatureApi {
    private final SignatureService service;
    private final String baseUrl;

    public SignatureApi(SignatureService service, String baseUrl) {
        this.service = service;
        this.baseUrl = baseUrl;
    }

    public String generateSimpleSecureUrl(String privateKey,Long expireTime,String tenantId,String filePath) throws Exception {
        SignRequest request = new SignRequest();
        request.setSecretKey(privateKey);
        request.setExpireTime(expireTime);
        request.setTenantId(tenantId);
        request.setFilePath(filePath);
        return generateSecureUrl(request);
    }

    public String generateSecureUrl( SignRequest request) throws Exception {
        String generateSignature = service.generateSignature(request);
        return request.buildSecureUrl(this.baseUrl, generateSignature);
    }

    public KeyPairDo generateKeyPair() {
        return service.generateKeyPair();
    }


}
